package days48;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;

public class day24 {
    public int getValue(int[] gifts, int n) {
        Stack<Integer> stack=new Stack<>();
        boolean k=false;
        int count=0;
        for (int i = 0; i < n; i++) {
            if(stack.empty()){
                stack.add(gifts[i]);
                count++;
                continue;
            }
            if(gifts[i]==stack.peek()){
                count++;
                k=true;
                continue;
            }else {
                    count--;
                if(count==0){
                    stack.pop();
                }
            }

        }
        if (!k){
            return 0;
        }
        return stack.peek();
    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String str1=scanner.nextLine();
        String str2=scanner.nextLine();

    }
}
